/**
 * 事件监听demo
 */
import 'package:flutter_benchu/utils/commonPkg.dart';

class EventDemoPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _EventDemoPageState();
}

class _EventDemoPageState extends State<EventDemoPage> {
  StreamSubscription logoutSubscription; //事件句柄

  @override
  void initState() {
    super.initState();
    //事件监听
    logoutSubscription = eventBus.on<BillFliterEvent>().listen((event) {
      Log.v('收到事件');
      Log.v(event);
    });
  }

  @override
  void dispose() {
    super.dispose();
    logoutSubscription?.cancel();
  }

  // 发送事件
  sendEvent() {
    eventBus.fire(BillFliterEvent(BillFliterState.inFliter));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('事件监听')),
      body: Column(
        children: [
          InkWell(
            onTap: sendEvent,
            child: Text("点击发送事件"), //切换页面
          ),
        ],
      ),
    );
  }
}
